import { ref, computed } from 'vue'
import { createGlobalState, useStorage } from '@vueuse/core'


//使用createGlobalState可以当个简单化的pinia
export const useGlobalState = createGlobalState(
    // computed(() => count.value * 2)
    () => {
        // state
        let count = ref({})

        // 持久化
        count = useStorage('count', count.value, localStorage, { mergeDefaults: true })

        // getters
        const doubleCount = () => {
            return count.value
        }

        // actions
        function increment(data: Object) {
            count.value = data
        }

        const clear = () => {
            count.value = {}
        }

        return { doubleCount, increment, clear }
    }
)